Skip to content

remove unsafe from iter_mut#15

Merged
nicolaskagami merged 1 commit into
mainfrom
nsk/safe-iter-mut
Mar 11, 2026
Merged

remove unsafe from iter_mut#15
nicolaskagami merged 1 commit into
mainfrom
nsk/safe-iter-mut

Conversation

@nicolaskagami

Copy link
Copy Markdown
Owner

What does this PR add?

  • Removes the only unsafe we have.

Details

  • A trivial benchmark on iter_mut shows up to 15% slower performance with this change. Since it does not affect lookup or insert it was deemed worth it just to keep the "unsafe-less" badge, for whatever it is worth.
  • iter_mut was unsafe as we simply kept values: &'a mut [V],. It's a bit annoying to prove to the compiler that our indices won't clash and therefore mut references won't alias. It would be trivial if we kept the value in the BTreeMap along with the Prefix but then we'd lose the contiguousness of values that helps with cache locality. Not to mention that the rest of the entry is not consulted on the lookup hot path.

@nicolaskagami
nicolaskagami merged commit 490f94c into main Mar 11, 2026
1 check passed
@nicolaskagami
nicolaskagami deleted the nsk/safe-iter-mut branch March 11, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant